<template>
    <div class="page-content-wrap">
        <page-title></page-title>
        <div class="page-content">
            <div class="page-flex-row">
                <div class="box-right">
                    <div class="search-box">
                        <div class="search-form">
                            <select-para style="width:100px;margin-right:5px" v-model="ruleForm.searchType"
                                :label.sync="ruleForm.searchTypeName" :options="searchTypeArr">
                            </select-para>
                            <el-input style="margin-right:5px" v-model="ruleForm.usernameLk"
                                v-if="ruleForm.searchType=='xm'"></el-input>
                            <el-input style="width:30%;margin-right:5px" v-model="ruleForm.emailLike"
                                v-if="ruleForm.searchType=='yx'"></el-input>
                            <el-input style="width:30%;margin-right:5px" v-model="ruleForm.empLoyeeNoLk"
                                v-if="ruleForm.searchType=='gh'"></el-input>
                            <el-button @click="clickQuery" type="success">搜索</el-button>
                            <el-button @click="resetForm" type="success">
                                <i class="iconfont icon-reset"></i>
                                重置
                            </el-button>
                        </div>
                        <div class="btn-wrap">

                            <el-button type="success" @click="addFun" icon="el-icon-circle-plus">新增
                            </el-button>
                            <el-button type="success" :loading="loading" @click="lockedFun"
                                :disabled="selection.length==0">锁定
                            </el-button>
                            <el-button type="success" @click="deleteFun" :disabled="selection.length==0"
                                icon="el-icon-delete" :loading="loading">删除
                            </el-button>
                            <el-button type="success" :loading="loading" @click="pwdReset"
                                :disabled="selection.length==0">重置
                            </el-button>
                            <!-- <el-dropdown @command="changeEdit" style="margin:0 5px">
                                <el-button>
                                    更多<i class="el-icon-arrow-down el-icon--right"></i>
                                </el-button>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item v-for="(item, index) in editType" :command="item" :key="index"
                                        :disabled="selection.length==0&&item.value!='export'&&item.value!='import'">
                                        {{item.label}}
                                    </el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown> -->
                            <el-button type="success" @click="adjustOrg" :disabled="selection.length==0">加入组
                            </el-button>
                            <el-button @click="setColumn" type="success">
                                <i class="iconfont icon-group10copy"></i> 列设置
                            </el-button>
                        </div>
                        <section class="scrollBar sel-colume" v-if="selTableVisible">
                            <h3>
                                <el-checkbox v-model="checked" @change="selAll">全选</el-checkbox>
                            </h3>
                            <el-checkbox-group v-model="staffTableSel" @change="selColumnChange">
                                <div v-for="(item,index) in tableData.headerData" :key="'list'+index">
                                    <el-checkbox :label="item.prop" :disabled="item.disabled">{{item.label}}
                                    </el-checkbox>
                                </div>
                            </el-checkbox-group>
                            <div class="sel-colume-button">
                                <el-button @click="cancelBtn">取消</el-button>
                                <el-button class="light-blue-btn" @click="selTableBtn">确定</el-button>
                            </div>
                        </section>
                    </div>
                    <div class="table-box">
                        <el-table stripe :key="tableKey" ref="table" height="100%" v-loading="loading"
                            :data="tableData.columnData" @row-dblclick="detailFun" @sort-change="sortChange"
                            @selection-change="handleSelectionChange">
                            <el-table-column type="selection" width="50"></el-table-column>
                            <el-table-column label="用户名" prop="username" v-if="showColumn('username')" min-width="200"
                                align="left">
                                <template slot-scope="scope">
                                    <img-show :url="scope.row.imsUrl" :name="scope.row.username"
                                        :subname="scope.row.roleName"></img-show>
                                </template>
                            </el-table-column>
                            <el-table-column label="工号" prop="employeeNo" v-if="showColumn('employeeNo')" width="120"
                                align="left" show-overflow-tooltip></el-table-column>
                            <el-table-column label="手机" prop="mobile" v-if="showColumn('mobile')" width="120"
                                show-overflow-tooltip align="center"></el-table-column>
                            <el-table-column label="邮箱" prop="email" v-if="showColumn('email')" min-width="200"
                                show-overflow-tooltip align="left"></el-table-column>
                            <el-table-column label="用户组" prop="deptName" v-if="showColumn('deptName')" width="150"
                                show-overflow-tooltip align="left">
                            </el-table-column>

                            <el-table-column label="隐藏号码" prop="isSecret" v-if="showColumn('isSecret')" width="100"
                                show-overflow-tooltip align="center">
                                <template slot-scope="scope">
                                    <div v-if="scope.row.isSecret">
                                        是
                                    </div>
                                    <div v-else>
                                        否
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column label="状态" prop="userStatusName" v-if="showColumn('userStatusName')"
                                width="100" show-overflow-tooltip align="center">
                            </el-table-column>
                            <el-table-column prop="crtName" label="创建人" v-if="showColumn('crtName')" align='center'
                                min-width="160">
                                <template slot-scope="scope">
                                    <template v-if="scope.row.crtNo == null">
                                        {{scope.row.crtName}}
                                    </template>
                                    <template v-else>
                                        {{scope.row.crtName}}【{{scope.row.crtNo}}】
                                    </template>
                                </template>
                            </el-table-column>
                            <el-table-column label="创建时间" prop="crtDt" v-if="showColumn('crtDt')" width="160"
                                align='center'>
                                <template slot-scope="scope">
                                    {{ scope.row.crtDt | formatDttm }}
                                </template>
                            </el-table-column>
                            <el-table-column prop="updName" label="更新人" v-if="showColumn('updName')" align='center'
                                min-width="160">
                                <template slot-scope="scope">
                                    <template v-if="scope.row.updNo == null">
                                        {{scope.row.updName}}
                                    </template>
                                    <template v-else>
                                        {{scope.row.updName}}【{{scope.row.updNo}}】
                                    </template>
                                </template></el-table-column>


                            <el-table-column label="更新时间" prop="updDt" v-if="showColumn('updDt')" width="160"
                                align='center'>
                                <template slot-scope="scope">
                                    {{ scope.row.updDt | formatDttm }}
                                </template>
                            </el-table-column>
                            <el-table-column label="最后登陆时间" prop="lastLoginDt" v-if="showColumn('lastLoginDt')"
                                width="160" align='center'>
                                <template slot-scope="scope">
                                    {{ scope.row.lastLoginDt | formatDttm }}
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" width="250" fixed="right">
                                <template slot-scope="scope">
                                    <!-- <el-button type="text" @click="authorzation(scope.row)">授权</el-button> -->
                                    <el-button type="text" @click="editFun(scope.row)">编辑</el-button>
                                    <!-- <el-button type="text" @click="disabledsingleFun(scope.row.id)">
                                        禁用
                                    </el-button> -->
                                    <span>
                                        <el-button type="text" @click="cancelUserByIdsFun(scope.row.id)"
                                            v-if="scope.row.userStatusId=='INACTIVE'">删除</el-button>
                                        <el-button type="text" @click="cancelUserByIdsFun2(scope.row.id)"
                                            v-if="scope.row.userStatusId=='ACTIVE'||scope.row.userStatusId=='LOCK'">注销
                                        </el-button>
                                        <el-button type="text" @click="recoverUserByIdsFun(scope.row.id)"
                                            v-if="scope.row.userStatusId=='CANCEL'">恢复</el-button>
                                    </span>
                                    <el-button type="text" v-if="scope.row.userStatusId=='LOCK'"
                                        @click="unlockFun(scope.row.id)">解锁</el-button>
                                    <el-button type="text" v-else @click="lockedFun2(scope.row.id)">锁定</el-button>
                                    <el-button type="text" @click="pwdReset2(scope.row.id)">重置</el-button>
                                    <el-button type="text" @click="adjustOrg2(scope.row)">加入组</el-button>

                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                    <div class="pagination">
                        <el-pagination :page-sizes="[5,10,15,30,50]" :page-size="tableData.pageSize"
                            layout="sizes,total,prev,pager,next" :total="tableData.total"
                            :current-page="tableData.currentPage" @size-change="handleSizeChange"
                            @current-change="handleCurrentChange">
                        </el-pagination>
                    </div>
                </div>
                <add-user ref="add" @refresh="queryDeptGroup"></add-user>
                <edit-user ref="edit" @refresh="queryDeptGroup"></edit-user>
                <el-dialog v-dialog-drag title="调整部门" :visible.sync="showorg" :append-to-body="true"
                    :close-on-click-modal="false">
                    <el-form :model="adjustForm" :rules="adjustFormrule" ref="adjustForm">
                        <el-row>
                            <el-col :span="23">
                                <el-form-item label="选择机构：" label-width="100px" prop="orgId">

                                    <select-dept v-model="adjustForm.orgId" :label.sync="adjustForm.orgName">
                                    </select-dept>
                                    <p class="tips">调整部门，则该人员将被从当前部门群里移除，移除后将不能查看该群的历史互动信息</p>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer">
                        <el-button type="primary" :loading="loading" @click="submitChange2" v-if="currentUserId">提 交
                        </el-button>
                        <el-button type="primary" :loading="loading" @click="submitChange" v-else>提 交</el-button>

                        <el-button @click="closeAdjustDia">取 消</el-button>
                    </div>
                </el-dialog>
                <!-- 用户授权 -->
                <el-dialog v-dialog-drag title="用户授权" :visible.sync="showcer" :append-to-body="true"
                    :close-on-click-modal="false">
                    <el-tabs v-model="activecer">
                        <el-tab-pane label="功能权限" name="1" lazy>
                            <func-auth :treeNode="treeNode" v-if="activecer == '1'" @refresh="initCer"></func-auth>
                        </el-tab-pane>
                        <el-tab-pane label="数据权限" name="2" lazy>
                            <data-auth :treeNode="treeNode" v-if="activecer == '2'" @refresh="initCer"></data-auth>
                        </el-tab-pane>
                    </el-tabs>
                </el-dialog>

                <el-dialog v-dialog-drag title="导入文件" :visible.sync="showimport" :append-to-body="true"
                    :close-on-click-modal="false">
                    <el-form>
                        <el-row>
                            <el-col :span="23">
                                <el-form-item label="上传文件：" label-width="100px">
                                    <el-upload style="display:inline-block;vertical-align:top;" ref="upload"
                                        accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                                        :data="uploadData" action="/api/api-sys/sys/user/importData"
                                        :auto-upload="false" :before-upload="beforeUpload" :on-success="uploadSuccess"
                                        :on-error="uploadError" name="uploadFile" :limit="1">
                                        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                                        <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
                                    </el-upload>
                                </el-form-item>
                                <el-form-item label="" label-width="100px">
                                    <p class="mesp">1.建立公司组织结构（还没有机构？去<b style="cursor: pointer;">创建</b>）</p>
                                    <p class="mesp">2.点击下载<b style="cursor: pointer;"
                                            @click="downLoadTem">《员工通讯录导入模板》</b></p>
                                    <p class="mesp">3.上传填写正确的通讯录导入模板</p>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer">
                        <el-button type="primary" :loading="loading" @click="doimportFun">提交</el-button>
                        <el-button @click="showimport=false">取消</el-button>
                    </div>
                </el-dialog>


            </div>
        </div>
    </div>
</template>

<script>
    import LeftRightLayout from '@/components/layout/LeftRightLayout';
    import uploadFile from '@/components/upload/uploadFile';
    import selectDept from '@/components/selectDept';
    import selectPara from '@/components/selectPara';
    import baseURL from '@/utils/baseURL'
    import moment from "moment";
    import addUser from './addUser';
    import editUser from './editUser';
    import funcAuth from './funcAuth';
    import dataAuth from './dataAuth';
    import imgShow from '@/components/avator/imgShow';


    import {
        queryDeptUser,
        changeUserDept,
        resetUserPwdFun,
        lockUserPwdFun,
        unlockUserPwdFun,
        cancelUserPwdFun,
        importUserFun,
        editUserPwdFun,
        cancelUserByIds,
        recoverUserByIds,
        deleteUserByIds
    } from "@/service/core/userManage";
    import {
        mapState
    } from 'vuex'
    import {
        isArray,
        http_builder_url
    } from '@/utils/Tools';
    import {
        columnSet,
        commPara,
    } from '@/mixins/mixins';

    export default {
        name: 'userManage',
        components: {
            selectPara,
            funcAuth,
            dataAuth,
            LeftRightLayout,
            moment,
            selectDept,
            editUser,
            addUser,
            imgShow,
            uploadFile
        },
        data() {
            return {
                activecer: '',
                activeName: '1',
                searchTypeArr: [{
                        label: '用户名',
                        value: 'xm'
                    },
                    {
                        label: '工号',
                        value: 'gh'
                    },
                    {
                        label: '邮箱',
                        value: 'yx'
                    }
                ],
                treeNode: {},
                path: [],
                showcer: false,
                tableData: [],
                loading2: false,
                showorg: false,
                adjustForm: {
                    orgId: '',
                    orgName: ''
                },
                filelist: [],
                ruleForm: {
                    searchType: 'xm',
                    searchTypeName: '用户名',
                    usernameLk: '',
                    emailLike: '',
                    empLoyeeNoLk: '',
                },
                rule: {

                },
                adjustFormrule: {
                    orgId: [{
                        required: true,
                        message: '请选择部门',
                        trigger: 'change'
                    }],
                },
                editType: [{
                    label: '重置员工密码',
                    value: 'czmm'
                }, {
                    label: '修改员工密码',
                    value: 'xgmm'
                }, {
                    label: '锁定账户',
                    value: 'sdzh'
                }, {
                    label: '解锁账户',
                    value: 'jszh'
                }, {
                    label: '禁用账户',
                    value: 'jyzh'
                }, {
                    label: 'Excel批量导入',
                    value: 'import'
                }, {
                    label: 'Excel批量导出',
                    value: 'export'
                }],
                currentUserId: '',
                showimport: false,
                tableData: {
                    columns: 'updDt',
                    orders: 'DESC',
                    pageSize: 15,
                    currentPage: 1,
                    total: 0,
                    headerData: [{
                            label: '用户名',
                            prop: 'username',
                            isShow: true,
                            disabled: true
                        },
                        {
                            label: '工号',
                            prop: 'employeeNo',
                            isShow: false
                        },

                        {
                            label: '手机',
                            prop: 'mobile',
                            isShow: true
                        },
                        {
                            label: '邮箱',
                            prop: 'email',
                            isShow: true
                        },
                        {
                            label: '用户组',
                            prop: 'deptName',
                            isShow: true
                        },

                        {
                            label: '隐藏号码',
                            prop: 'isSecret',
                            isShow: false
                        },

                        {
                            label: '状态',
                            prop: 'userStatusName',
                            isShow: true,
                        },

                        {
                            label: '创建人',
                            prop: 'crtName',
                            isShow: false
                        },
                        {
                            label: '创建时间',
                            prop: 'crtDt',
                            isShow: false
                        },
                        {
                            label: '更新人',
                            prop: 'updName',
                            isShow: false
                        },

                        {
                            label: '更新时间',
                            prop: 'updDt',
                            isShow: false
                        },

                        {
                            label: '最后登陆时间',
                            prop: 'lastLoginDt',
                            isShow: true
                        },


                    ],
                    columnData: []
                },
                loading: false,
                selection: [],
            }
        },
        created() {
            this.clickQuery()
        },
        mixins: [columnSet, commPara],
        computed: {
            ...mapState({
                token: state => state.token.token,
                
            }),
            uploadData() {
                return {
                    token: this.token,
                }
            }
        },
        methods: {
            initCer() {
                this.clickQuery()
                this.showcer = false
            },
            authorzation(item) {

                this.activecer = '';
                this.$nextTick(() => {
                    this.activecer = '1';
                })
                this.treeNode = item
                this.showcer = true
            },
            beforeUpload(file) {
                let type = file.name.split('.').pop();
                if (['xls', 'xlsx'].indexOf(type) == -1) {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '只能上传Excel文件！'
                    })
                    this.loading = false;
                    return false
                }
                return true
            },
            uploadSuccess(response, file, fileList) {
                this.loading = false;
                this.clickQuery()
                this.showimport = false
            },
            uploadError(err, file, fileList) {
                this.loading = false;
            },
            submitFun() {
                this.loading = true;
                this.$refs.upload.submit();
            },
            downloadTmp() {
                window.location.href = "/api/sys/atth/download?id=111099564"
            },
            submitChange() {
                let ids = this.selection.map(item => item.id).join(',');
                this.$refs.adjustForm.validate(valid => {
                    if (valid) {
                        let confirmMsg = "确认调整选中用户的部门？";
                        this.$confirm(confirmMsg, {
                            type: 'warning',
                            title: '提示'
                        }).then(() => {
                            let params = {
                                ids: ids,
                                deptId: this.adjustForm.orgId,
                                sourceDeptId: '',
                            }
                            this.loading = true
                            changeUserDept(params).then(res => {
                                if (res.data.code == 1000) {
                                    this.$notify({
                                        title: '提示',
                                        type: 'success',
                                        message: '提交成功'
                                    });
                                    this.showorg = false;
                                    this.queryDeptGroup()
                                }
                                this.loading = false

                            })
                            this.loading = false;
                        })
                    }
                })

            },
            submitChange2() {
                this.$refs.adjustForm.validate(valid => {
                    if (valid) {
                        let confirmMsg = "确认调整选中用户的部门？";
                        this.$confirm(confirmMsg, {
                            type: 'warning',
                            title: '提示'
                        }).then(() => {
                            let params = {
                                ids: this.currentUserId,
                                deptId: this.adjustForm.orgId,
                                sourceDeptId: '',
                            }
                            this.loading = true
                            changeUserDept(params).then(res => {
                                if (res.data.code == 1000) {
                                    this.$notify({
                                        title: '提示',
                                        type: 'success',
                                        message: '提交成功'
                                    });
                                    this.showorg = false;
                                    this.queryDeptGroup()
                                }
                                this.loading = false

                            })
                            this.loading = false;
                        })
                    }
                })

            },
            closeAdjustDia() {
                this.adjustForm = {
                    orgId: '',
                    orgName: ''
                }
                this.showorg = false
            },
            adjustOrg() {
                this.currentUserId = ''
                this.showorg = true
                setTimeout(() => {
                    this.$refs.adjustForm.resetFields();
                }, 100);

            },
            adjustOrg2(item) {
                this.currentUserId = item.id
                this.showorg = true
                setTimeout(() => {
                    this.$refs.adjustForm.resetFields();
                }, 100);

            },
            changeEdit(val) {
                if (val.value == 'czmm') {
                    this.pwdReset()
                } else if (val.value == 'xgmm') {
                    this.editMmFun()
                } else if (val.value == 'sdzh') {
                    this.lockedFun()
                } else if (val.value == 'jszh') {
                    this.unlockFun()
                } else if (val.value == 'jyzh') {
                    this.disabledFun()
                } else if (val.value == 'export') {
                    this.exportFun()
                } else if (val.value == 'import') {
                    this.importFun()
                }
            },
            clickQuery() {
                this.tableData.currentPage = 1;
                this.queryDeptGroup();
            },
            resetForm() {
                this.ruleForm.emailLike = '';
                this.ruleForm.empLoyeeNoLk = ''
                this.ruleForm.usernameLk = ''
                this.tableData.currentPage = 1;
                this.queryDeptGroup();
            },
            disabledsingleFun(id) {
                this.$confirm("被禁用的账户将不能使用系统，但之前的历史数据将保留，是否确认禁用？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let params = {
                        ids: id,
                        userStatusId: 'CANCEL'
                    };
                    this.loading = true;
                    cancelUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "禁用成功！",
                                type: "success"
                            });
                            this.clickQuery();
                        }
                        this.loading = false;
                    });
                    this.loading = false;
                });
            },
            sortChange(data) {
                if (data.order == "ascending") {
                    this.tableData.orders = "ASC";
                } else if (data.order == "descending") {
                    this.tableData.orders = "DESC";
                }
                this.tableData.columns = data.prop;
                this.queryDeptGroup();
            },
            addFun() { // 新增用户
                this.$refs.add.showLayout();
            },
            importFun() {

                this.showimport = true
                this.$refs.upload.clearFiles();
            },
            doimportFun() {
                this.$confirm("导入数据，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    this.$refs.upload.submit();
                })
            },
            exportFun() {
                let params = {
                    orders: this.tableData.orders, // 排序顺序
                    columns: this.tableData.columns, // 排序字段
                    usernameLk: this.ruleForm.usernameLk,
                    email: this.ruleForm.email,
                    empLoyeeNoLk: this.ruleForm.empLoyeeNoLk,
                    userStatusIdIn: 'INACTIVE,ACTIVE,LOCK'
                }
                if (params.deptId == 'ALL' || params.deptId == 'YFPBMYG' || params.deptId ==
                    'WFPBMYG') {
                    params.deptId = ''
                }

                let newpa = http_builder_url('', params);
                let exportProp = this.staffTableSel.join(',');
                window.location.href = baseURL.url + "/api-sys/sys/user/exportData" + newpa + "&token=" + this
                    .$store.state.token.token + '&heads=' + exportProp.replace('cs,', '');
            },
            downLoadTem() {
                window.location.href = baseURL.url + "/api-sys/sys/user/downloadTemplate" + "?token=" + this
                    .$store.state.token.token
            },

            editMmFun() {
                this.$prompt('请输入新密码', '修改密码', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: '',
                    inputErrorMessage: ''
                }).then(({
                    value
                }) => {
                    let ids = this.selection.map(item => item.id).join();
                    let params = {
                        ids: ids,
                        newPwd: value
                    };
                    editUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "修改成功！",
                                type: "success"
                            });
                            this.clickQuery();
                        }
                    });
                })
            },
            // 删除
            cancelUserByIdsFun(id) {
                this.$confirm("确认删除所选账号信息，删除后不可恢复，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let params = {
                        ids: id
                    };
                    this.loading = true
                    deleteUserByIds(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "删除成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }
                        this.loading = false;
                    });
                });
            },
            deleteFun() {
                let ids = this.selection.map(item => item.id).join();
                this.cancelUserByIdsFun(ids)
            },
            // 注销
            cancelUserByIdsFun2(id) {
                this.$confirm("确认注销所选账号，注销后账号不可使用，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let params = {
                        ids: id
                    };
                    this.loading = true
                    cancelUserByIds(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "注销成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }
                    });
                    this.loading = false;
                });
            },
            //恢复
            recoverUserByIdsFun(id) {
                this.$confirm("确认恢复所选账号，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let params = {
                        ids: id
                    };
                    this.loading = true
                    recoverUserByIds(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "恢复成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }
                        this.loading = false;
                    });
                });
            },
            disabledFun() {
                this.$confirm("被禁用的账户将不能使用系统，但之前的历史数据将保留，是否确认禁用？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let ids = this.selection.map(item => item.id).join();
                    let params = {
                        ids: ids
                    };
                    this.loading = true
                    cancelUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "禁用成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }
                        this.loading = false;
                    });
                });
            },
            unlockFun(id) {
                this.$confirm("解锁账户将把锁定的账户可使用，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let params = {
                        ids: id
                    };
                    this.loading = true
                    unlockUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "解锁成功！",
                                type: "success"
                            });
                            this.clickQuery();
                        }
                        this.loading = false;
                    });
                    this.loading = false;
                });
            },

            lockedFun() {
                this.$confirm("锁定期间的账户在解锁前暂时不能继续使用，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let ids = this.selection.map(item => item.id).join();
                    let params = {
                        ids: ids
                    };
                    this.loading = true
                    lockUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "锁定成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }

                    });
                    this.loading = false;
                });
            },
            lockedFun2(id) {
                this.$confirm("锁定期间的账户在解锁前暂时不能继续使用，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let ids = this.selection.map(item => item.id).join();
                    let params = {
                        ids: id
                    };
                    this.loading = true;
                    lockUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "锁定成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }
                    });
                    this.loading = false;
                });
            },
            pwdReset() {
                this.$confirm("重置后将选择的员工密码重置为“配置中心”下“密码策略”中设置的密码，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let ids = this.selection.map(item => item.id).join();
                    let params = {
                        ids: ids
                    };
                    this.loading = true
                    resetUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "重置成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }
                    });
                    this.loading = false;
                });
            },
            pwdReset2(id) {
                this.$confirm("重置后将选择的员工密码重置为“配置中心”下“密码策略”中设置的密码，是否确认？", {
                    title: "提示",
                    type: "warning"
                }).then(() => {
                    let ids = this.selection.map(item => item.id).join();
                    let params = {
                        ids: id
                    };
                    this.loading = true
                    resetUserPwdFun(params).then(response => {
                        if (response.data.code == 1000) {
                            this.$notify({
                                title: "提示",
                                message: "重置成功！",
                                type: "success"
                            });
                            this.loading = false;
                            this.clickQuery();
                        }
                    });
                    this.loading = false;
                });
            },
            editFun(row) { // 编辑
                this.$refs.edit.showLayout(row);
            },
            detailFun(row) { // 明细
                this.$refs.detail.showLayout(row);
            },
            handleCurrentChange(val) {
                this.tableData.currentPage = val;
                this.queryDeptGroup();
            },
            handleSizeChange(val) {
                this.tableData.currentPage = 1
                this.tableData.pageSize = val;
                this.queryDeptGroup();
            },
            handleSelectionChange(selection) {
                this.selection = selection;
            },

            queryDeptGroup() { // 查询机构下的用户列表

                let params = {
                    orders: this.tableData.orders, // 排序顺序
                    columns: this.tableData.columns, // 排序字段
                    startRow: this.tableData.currentPage,
                    rowSize: this.tableData.pageSize,
                    usernameLk: this.ruleForm.usernameLk,
                    emailLike: this.ruleForm.emailLike,
                    empLoyeeNoLk: this.ruleForm.empLoyeeNoLk,
                    
                }
                this.loading = true;
                queryDeptUser(params).then(res => {
                    if (res.data.code == 1000) {
                        let data = res.data.data;
                        if (Array.isArray(data.data)) {
                            this.tableData.columnData = [...data.data];
                            this.tableData.total = data.total;
                        } else {
                            this.tableData.columnData = [];
                            this.tableData.total = 0;
                        }
                    }
                    this.loading = false;
                }).catch(error => {
                    this.loading = false;
                })
            },
        }
    }

</script>

<style lang="scss" scoped>
    .m-title {
        height: 22px;
        line-height: 22px;
        font-size: 16px;
        font-weight: 500;
        margin-bottom: 10px;
        font-weight: bold !important
    }

    .m-title /deep/ .el-breadcrumb__inner {
        font-weight: bold !important;
    }

    .mesp {
        font-size: 12px;
        color: #999
    }

</style>
